<?php

require_once('../../config/maptrick.conf.php');
require_once(SITE_ROOT . 'class/bean/Country.class.php');
require_once(SITE_ROOT . 'class/bean/Division.class.php');
require_once(SITE_ROOT . 'class/bean/League.class.php');
require_once(SITE_ROOT . 'class/db/DBCountry.class.php');
require_once(SITE_ROOT . 'class/db/DBDivision.class.php');
require_once(SITE_ROOT . 'class/db/DBLeague.class.php');

try {
	$dbcountry = new DBCountry();
	$dbdivision = new DBDivision();
	$dbleague = new DBLeague();
	
	$countries = $dbcountry->getCountries();
	foreach ($countries as $country) {
		$divisions = $dbdivision->getDivisionsByCountry($country);
		foreach ($divisions as $division) {
			$leagues = $dbleague->getLeaguesByDivision($division);
			$division->setSize(count($leagues));
		}
		$dbdivision->saveDivisions($divisions);
	}
	
	$newmoon = new Country();
	$newmoon->setCountryID(90);
	$dbleague->deleteLeaguesByCountry($newmoon);
	$dbdivision->deleteDivisionsByCountry($newmoon);
}
catch (Exception $e) {
	echo $e->getMessage();
}

?>